<?php


namespace app\index\model;

use app\index\model\Cate;
use think\Model;

class Article extends Model
{
    public function getAllArticles($id){
        $cate = new \app\index\model\Cate();
        $childid = $cate->getChildrenid($id);
        $cateid = $childid;
        $cateid[] = (int)$id;
        $Articles = Article::where('cateid','in',$cateid)->order('id desc')->paginate(2);
        return $Articles;
    }
    public function getHotRes($id){
        $cate = new \app\index\model\Cate();
        $childid = $cate->getChildrenid($id);
        $cateid = $childid;
        $cateid[] = (int)$id;
        $HotArticles = Article::where('cateid','in',$cateid)->order('click desc')->limit(3)->select();
        return $HotArticles;
    }
    public static function getNewArticle(){
        $newArticleRes = db('article')->field('a.id,a.title,a.des,a.thumb,a.click,a.zan,a.time,c.catename,a.cateid,c.id,c.type')
        ->alias('a')->join('bk_cate c','a.cateid=c.id')->order('a.id desc')->limit(5)->select();
        return $newArticleRes;
     }
}